//
//  XHPushGuideView.m
//  BSNoAnswer
//
//  Created by Tiffany宝 on 16/5/13.
//  Copyright © 2016年 Tiffany. All rights reserved.
//

#import "XHPushGuideView.h"

@implementation XHPushGuideView

+(instancetype)guideView{
    //  加载xib loadNibNamed: NSStringFromClass(self) ,不用再写@"xib名称"了
    return [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil].lastObject;
}

//推送引导界面
+(void)show{
    // *** 把 key 抽取出来
    NSString *key = @"CFBundleShortVersionString";
    NSString *currentVersion = [NSBundle mainBundle].infoDictionary[key];
    NSString *lastVersion = [[NSUserDefaults standardUserDefaults] objectForKey:key];
    //判断版本号是否一致
    if (![currentVersion isEqualToString:lastVersion]) {
        //说明是新版本
        XHPushGuideView *guideView = [XHPushGuideView guideView];
        //拿到window
        UIWindow *window = [UIApplication sharedApplication].keyWindow;
        //设置frame
        guideView.frame = window.bounds;
        [window addSubview:guideView];
        //记录版本号
        [[NSUserDefaults standardUserDefaults]setObject:currentVersion forKey:key];
        //同步
        [[NSUserDefaults standardUserDefaults]synchronize];
    }
}

- (IBAction)finish{
    
    [self removeFromSuperview];
    XHLogFunc;
}

@end
